<?php
require_once(dirname(dirname(dirname(__FILE__))) . '/app.php');

need_manager();
need_auth('super');

if (isset($_GET['isdao']) && intval($_GET['isdao']) == 1) {
	$name = '用户配送信息-'.date('Y-m-d');
	$kn = array(
				'id' => 'ID',
				'name' => '姓名',
				'mobile' => '电话',
				'province' => '省',
				'city' => '市',
				'area' => '区',
				'street' => '街道',
		);
	
	$sql = "select * from address  group by mobile order by id asc  limit 0,999999";
	$users = DB::GetQueryResult($sql,false);
	/**
	$users = DB::LimitQuery('address', array(
		'order' => 'ORDER BY id asc',
		'size' => 1999999,
		'offset' => 0,
	));
	**/
	
	$list = array();
	foreach( $users AS $one ) {
		$tmp = array();
		$tmp['id'] = $one['id'];
		$tmp['name'] = $one['name'];
		$tmp['mobile'] = $one['mobile'];
		$tmp['province'] = $one['province'];
		$tmp['city'] = $one['city'];
		$tmp['area'] = $one['area'];
		$tmp['street'] = $one['street'];
		$list[] = $tmp;
	}
	down_xls($list, $kn, $name);

}

/* build condition */
$condition = array('');


$sql_count = "select count(DISTINCT(mobile)) as count from address   ";
$count = DB::GetQueryResult($sql_count,true);
$count =$count['count'];

//$count = Table::Count('address', $condition);
list($pagesize, $offset, $pagestring) = pagestring($count, 20);
//SELECT * FROM `address`  group BY mobile order by id desc 
$sql = "select * from address  group by mobile order by id desc  limit {$offset},{$pagesize}";
$users = DB::GetQueryResult($sql,false);

//GetQueryResult
/**
$users = DB::LimitQuery('address', array(
	'condition' => $condition,
	'order' => 'ORDER BY id DESC group by mobile ',
	'size' => $pagesize,
	'offset' => $offset,
));
**/
include template('manage_user_peisong');
